<?
include_once "./naiveBayesClassifier.php";
include_once "./NearestNeighbourClassifier.php";


class ClassificationHandler {

	public function __construct() {}
	
	
	/* 
		Function that takes all senty post, and for each sentence, firstly classifies it as subjective
		or objective. In the first case, it classifies it as positive or negative.
	*/
	public function classifyAll($all_posts) {
		
		$nearestNeighbour = new NearestNeighbourClassifier(3);
		$naiveBayes = new NaiveBayesClassifier();
		
		$neutralityClassifier = $nearestNeighbour;
		$sentimentClassifier = $naiveBayes;
		
		foreach ($all_posts as &$current_post)
		{
			foreach($current_post -> message['sentences'] as &$sentence)
				if ($neutralityClassifier -> classify($sentence['text']) == 'subj') {
					$score = $sentimentClassifier -> classify($sentence['text']);
					/* 10 for positive and 0 for negative */
					if ($score=="pos")
						$sentence['s_value'] = 10;
				}
				else
					$sentence['s_value'] = 5;
			
			
			/**************** NEW SET OF COMMENT for the message *********/
			foreach ($current_post->comments as &$current_post_comments)
				/****************NEW set of sentences for this comment *********/
				foreach($current_post_comments['sentences'] as &$sentence)
					if ($neutralityClassifier -> classify($sentence['text']) == 'subj') {
						$score = $sentimentClassifier -> classify($sentence['text']);
						/* 10 for positive and 0 for negative */
						if ($score=="pos")
							$sentence['s_value'] = 10;
					}
					else
						$sentence['s_value'] = 5;
		}
		return $all_posts;
	}


}